package com.oa.ylms.apps.business.assess.impl;

import java.util.List;

import com.oa.ylms.apps.business.assess.IAssessItemService;
import com.oa.ylms.apps.business.assess.IItemCategoryService;
import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.assess.IAssessItemDao;
import com.oa.ylms.apps.entity.assess.AssessItemValue;
import com.oa.ylms.apps.entity.assess.AssessModelValue;

public class AssessItemServiceImpl implements IAssessItemService {

	private IAssessItemDao dao;
	private AssessItemValue assessItem;
	private IItemCategoryService itemCategoryService;
	private List<AssessItemValue> list;

	public int addAssessItem(String itemName, Integer categoryId,
			Integer highScore) throws Exception {
		assessItem.setItemName(itemName);
		assessItem.setItemCategory(itemCategoryService
				.queryItemCategoryByCategoryId(categoryId));
		assessItem.setHighScore(highScore);
		assessItem.setStates(IDEDStates.ENABLE);
		return dao.addAssessItem(assessItem);
	}

	public String deleteAssessItem(String itemIds) throws Exception {
		String unDelIds = "";
		String[] arrayItemId = itemIds.split(",");
		for (String itemIdStr : arrayItemId) {
			int itemId = Integer.parseInt(itemIdStr);
			assessItem = queryAssessItemByItemId(itemId);
			assessItem.setStates(IDEDStates.DELETE);
			boolean result = dao.editAssesItem(assessItem);
			if (result == false) {
				unDelIds = itemId + ",";
				continue;
			}
		}
		return unDelIds;
	}

	public List<AssessItemValue> queryAllAssessItem() throws Exception {

		return dao.queryAllAssessItem();
	}

	public List<AssessItemValue> queryAssessItemByCategoryId(int categoryId)
			throws Exception {

		return dao.queryAssessItemByCategoryId(categoryId);
	}

	public List<AssessItemValue> queryAssessItemByItemIds(String itemIds)
			throws Exception {
		String[] arrayItemId = itemIds.split(",");
		for (String itemIdStr : arrayItemId) {
			int itemId = Integer.parseInt(itemIdStr);
			assessItem = queryAssessItemByItemId(itemId);
			list.add(assessItem);
		}
		return list;
	}

	public AssessItemValue queryAssessItemByItemId(int itemId) throws Exception {
		return dao.queryAssessItemByItemId(itemId);
	}

	public boolean deleteAssessItem(int itemId,int modelId) throws Exception {
		assessItem = queryAssessItemByItemId(itemId);
		if(assessItem!=null)
		{
			assessItem.setStates(IDEDStates.DELETE);
			return dao.editAssesItem(assessItem);
		}
	
		return false;
	}

	public boolean toDisable(int itemId) throws Exception {
		assessItem = queryAssessItemByItemId(itemId);
		if (assessItem != null) {
			assessItem.setStates(IDEDStates.DISABLE);
			return dao.editAssesItem(assessItem);
		}
		return false;
	}

	public boolean toEnable(int itemId) throws Exception {
		assessItem = queryAssessItemByItemId(itemId);
		if (assessItem != null) {
			assessItem.setStates(IDEDStates.ENABLE);
			return dao.editAssesItem(assessItem);
		}
		return false;
	}

	public IAssessItemDao getDao() {
		return dao;
	}

	public void setDao(IAssessItemDao dao) {
		this.dao = dao;
	}

	public AssessItemValue getAssessItem() {
		return assessItem;
	}

	public void setAssessItem(AssessItemValue assessItem) {
		this.assessItem = assessItem;
	}

	public List<AssessItemValue> getList() {
		return list;
	}

	public void setList(List<AssessItemValue> list) {
		this.list = list;
	}

}
